package top.mccat.raven.combatstatus.utils;

import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Color;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import top.mccat.raven.combatstatus.domain.CombatConfig;

/**
 * @author Distance
 * @date 2022/6/14
 */
public class MsgUtils {
    private CombatConfig combatConfig;

    public MsgUtils(CombatConfig combatConfig) {
        this.combatConfig = combatConfig;
        if(combatConfig == null){
            this.combatConfig = new CombatConfig();
            this.combatConfig.setPluginName("&a[&cCombatStatus&a]");
        }
    }

    /**
     * 发送消息工具
     * @param player 玩家实体
     * @param msg 消息
     */
    public void sendToPlayer(Player player, String msg){
        player.sendMessage(ColorUtils.parseColorStr(combatConfig.getPluginName()+msg));
    }

    /**
     * 发送title工具
     * @param player 玩家对象
     * @param title 标题
     * @param subTitle 子标题
     * @param fadeIn 淡入时间，时长为tick （20tick = 1 second）
     * @param stay 持续时间，tick
     * @param fadeOut 淡出时间，时长为tick
     */
    public void sendTitle(Player player, String title, String subTitle, int fadeIn, int stay, int fadeOut){
        player.sendTitle(ColorUtils.parseColorStr(title),ColorUtils.parseColorStr(subTitle),fadeIn,stay,fadeOut);
    }

    public void sendActionBar(Player player, String text){
        TextComponent textComponent = new TextComponent();
        textComponent.setText(ColorUtils.parseColorStr(text));
        player.spigot().sendMessage(ChatMessageType.ACTION_BAR,textComponent);
    }

    public void sendToConsole(CommandSender commandSender, String msg){
        commandSender.sendMessage(ColorUtils.parseColorStr(combatConfig.getPluginName()+msg));
    }

    public void setCombatConfig(CombatConfig combatConfig) {
        this.combatConfig = combatConfig;
    }
}
